import type { HomeDataResult, InformationPageListResData } from './types';
import type { IResData } from '../indexTypes';
import { exc } from '../apiRoot';
import { defHttp } from '@/utils/http';

const Api = {
  informationPageList: exc + 'information/list',
  informationDetails: exc + 'information/get',
  clickRate: exc + 'clickRate',
  homeData: exc + 'indexData',
};

/**
 *
 * 获取资讯列表
 * @export
 * @param {{ module: number; moduleSub: number }} data
 * @return {*}  {Promise<IResData<InformationPageListResData>>}
 */
export function informationPageList(data: {
  module: number;
  moduleSub: number;
  size: number;
  current: number;
}): Promise<IResData<InformationPageListResData>> {
  const code = data.moduleSub ? `${data.module}/${data.moduleSub}` : data.module;
  return defHttp.get({
    url: `${Api.informationPageList}/${code}?size=${data.size}&current=${data.current}`,
  });
}



/**
 * @description 获取资讯详情
 * @date 21/07/2022
 * @export
 * @param {(string | number)} id 资讯id
 */
export function informationDetails(id: string | number) {
  return defHttp.get<InformationPageListResData>({
    url: Api.informationDetails + `/${id}`,
  });
}

/**
 * 资讯文章提交阅读记录
 * @export
 * @param {number} id 资讯id
 * @param {number} [type=4] 资讯
 * @return {*}
 */
export function clickRate(id: number, type: number = 4): Promise<number> {
  return defHttp.get({
    url: Api.clickRate + `/${type}/${id}`,
  });
}

/**
 * @description 获取首页数据总合
 * @date 11/01/2024
 * @export
 */
export function getHomeData() {
  return defHttp.get<HomeDataResult>({
    url: Api.homeData,
  });
}